package cn.bellychang.whiteboard;

/**
 * @author ChangLiang
 * @date 2021/3/7
 */
public class CatSortSolution {

    public Cat[] sortByColor(Cat[] cats){
        for(int i=0; i<cats.length; i++){
            if(cats[i].getColor().equals("black")){
                int j = i+1;
                while(j<cats.length && !cats[j].getColor().equals("white")){
                    j++;
                }
                if (j == cats.length) {
                    break;
                } else {
                    swap(i, j, cats);
                }
            }
        }
        return cats;
    }

    private void swap(int i, int j, Cat[] cats) {
        Cat temp = cats[i];
        cats[i] = cats[j];
        cats[j] = temp;
    }
}

class Cat{
    private String color;

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    @Override
    public String toString() {
        return "Cat{" +
                "color='" + color + '\'' +
                '}';
    }
}
